<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><link rel="stylesheet" type="text/css" href="style.css" /><script type="text/javascript" src="highlight.js"></script></head><body><pre><span class="hs-comment">-----------------------------------------------------------------------------</span><span>
</span><span id="line-2"></span><span class="hs-comment">-- |</span><span>
</span><span id="line-3"></span><span class="hs-comment">-- Module      :  Distribution.Simple.Program.Internal</span><span>
</span><span id="line-4"></span><span class="hs-comment">--</span><span>
</span><span id="line-5"></span><span class="hs-comment">-- Maintainer  :  cabal-devel@haskell.org</span><span>
</span><span id="line-6"></span><span class="hs-comment">-- Portability :  portable</span><span>
</span><span id="line-7"></span><span class="hs-comment">--</span><span>
</span><span id="line-8"></span><span class="hs-comment">-- Internal utilities used by Distribution.Simple.Program.*.</span><span>
</span><span id="line-9"></span><span>
</span><span id="line-10"></span><span class="hs-keyword">module</span><span> </span><span class="hs-identifier">Distribution.Simple.Program.Internal</span><span> </span><span class="hs-special">(</span><span>
</span><span id="line-11"></span><span>    </span><span class="annot"><a href="Distribution.Simple.Program.Internal.html#stripExtractVersion"><span class="hs-identifier">stripExtractVersion</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-12"></span><span>  </span><span class="hs-special">)</span><span> </span><span class="hs-keyword">where</span><span>
</span><span id="line-13"></span><span>
</span><span id="line-14"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="../../base/src/Prelude.html#"><span class="hs-identifier">Prelude</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-15"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="Distribution.Compat.Prelude.html"><span class="hs-identifier">Distribution.Compat.Prelude</span></a></span><span>
</span><span id="line-16"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="Distribution.Utils.Generic.html"><span class="hs-identifier">Distribution.Utils.Generic</span></a></span><span class="hs-special">(</span><span class="annot"><a href="Distribution.Utils.Generic.html#safeTail"><span class="hs-identifier">safeTail</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-17"></span><span>
</span><span id="line-18"></span><span class="hs-comment">-- | Extract the version number from the output of 'strip --version'.</span><span>
</span><span id="line-19"></span><span class="hs-comment">--</span><span>
</span><span id="line-20"></span><span class="hs-comment">-- Invoking &quot;strip --version&quot; gives very inconsistent results. We ignore</span><span>
</span><span id="line-21"></span><span class="hs-comment">-- everything in parentheses (see #2497), look for the first word that starts</span><span>
</span><span id="line-22"></span><span class="hs-comment">-- with a number, and try parsing out the first two components of it. Non-GNU</span><span>
</span><span id="line-23"></span><span class="hs-comment">-- 'strip' doesn't appear to have a version flag.</span><span>
</span><span id="line-24"></span><span class="annot"><a href="Distribution.Simple.Program.Internal.html#stripExtractVersion"><span class="hs-identifier hs-type">stripExtractVersion</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../base/src/GHC.Base.html#String"><span class="hs-identifier hs-type">String</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../base/src/GHC.Base.html#String"><span class="hs-identifier hs-type">String</span></a></span><span>
</span><span id="line-25"></span><span id="stripExtractVersion"><span class="annot"><span class="annottext">stripExtractVersion :: String -&gt; String
</span><a href="Distribution.Simple.Program.Internal.html#stripExtractVersion"><span class="hs-identifier hs-var hs-var">stripExtractVersion</span></a></span></span><span> </span><span id="local-6989586621679618507"><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679618507"><span class="hs-identifier hs-var">str</span></a></span></span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-26"></span><span>  </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621679618506"><span class="annot"><span class="annottext">numeric :: String -&gt; Bool
</span><a href="#local-6989586621679618506"><span class="hs-identifier hs-var hs-var">numeric</span></a></span></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;&quot;</span></span><span>    </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">False</span></span><span>
</span><span id="line-27"></span><span>      </span><span class="annot"><a href="#local-6989586621679618506"><span class="hs-identifier hs-var">numeric</span></a></span><span> </span><span class="hs-special">(</span><span id="local-6989586621679618505"><span class="annot"><span class="annottext">Char
</span><a href="#local-6989586621679618505"><span class="hs-identifier hs-var">x</span></a></span></span><span class="annot"><span class="hs-glyph hs-type">:</span></span><span class="annot"><span class="annottext">String
</span><span class="hs-identifier">_</span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Char -&gt; Bool
</span><a href="../../base/src/GHC.Unicode.html#isDigit"><span class="hs-identifier hs-var">isDigit</span></a></span><span> </span><span class="annot"><span class="annottext">Char
</span><a href="#local-6989586621679618505"><span class="hs-identifier hs-var">x</span></a></span><span>
</span><span id="line-28"></span><span>
</span><span id="line-29"></span><span>      </span><span class="hs-comment">-- Filter out everything in parentheses.</span><span>
</span><span id="line-30"></span><span>      </span><span class="annot"><a href="#local-6989586621679618503"><span class="hs-identifier hs-type">filterPar'</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Int</span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="../../base/src/GHC.Base.html#String"><span class="hs-identifier hs-type">String</span></a></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="../../base/src/GHC.Base.html#String"><span class="hs-identifier hs-type">String</span></a></span><span class="hs-special">]</span><span>
</span><span id="line-31"></span><span>      </span><span id="local-6989586621679618503"><span class="annot"><span class="annottext">filterPar' :: Int -&gt; [String] -&gt; [String]
</span><a href="#local-6989586621679618503"><span class="hs-identifier hs-var hs-var">filterPar'</span></a></span></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-identifier">_</span></span><span> </span><span class="hs-special">[</span><span class="hs-special">]</span><span>                   </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">[</span><span class="hs-special">]</span><span>
</span><span id="line-32"></span><span>      </span><span class="annot"><a href="#local-6989586621679618503"><span class="hs-identifier hs-var">filterPar'</span></a></span><span> </span><span id="local-6989586621679618502"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679618502"><span class="hs-identifier hs-var">n</span></a></span></span><span> </span><span class="hs-special">(</span><span id="local-6989586621679618501"><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679618501"><span class="hs-identifier hs-var">x</span></a></span></span><span class="annot"><span class="hs-glyph hs-type">:</span></span><span id="local-6989586621679618500"><span class="annot"><span class="annottext">[String]
</span><a href="#local-6989586621679618500"><span class="hs-identifier hs-var">xs</span></a></span></span><span class="hs-special">)</span><span>
</span><span id="line-33"></span><span>        </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679618502"><span class="hs-identifier hs-var">n</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Bool
forall a. Ord a =&gt; a -&gt; a -&gt; Bool
</span><span class="hs-operator hs-var">&gt;=</span></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">0</span></span><span> </span><span class="annot"><span class="annottext">Bool -&gt; Bool -&gt; Bool
</span><span class="hs-operator hs-var">&amp;&amp;</span></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;(&quot;</span></span><span> </span><span class="annot"><span class="annottext">String -&gt; String -&gt; Bool
forall a. Eq a =&gt; [a] -&gt; [a] -&gt; Bool
</span><a href="../../base/src/Data.OldList.html#isPrefixOf"><span class="hs-operator hs-var">`isPrefixOf`</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679618501"><span class="hs-identifier hs-var">x</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int -&gt; [String] -&gt; [String]
</span><a href="#local-6989586621679618503"><span class="hs-identifier hs-var">filterPar'</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679618502"><span class="hs-identifier hs-var">n</span></a></span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="../../base/src/GHC.Num.html#%2B"><span class="hs-operator hs-var">+</span></a></span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">1</span></span><span class="hs-special">)</span><span> </span><span class="hs-special">(</span><span class="hs-special">(</span><span class="annot"><span class="annottext">String -&gt; String
forall a. [a] -&gt; [a]
</span><a href="Distribution.Utils.Generic.html#safeTail"><span class="hs-identifier hs-var">safeTail</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679618501"><span class="hs-identifier hs-var">x</span></a></span><span class="hs-special">)</span><span class="annot"><span class="annottext">String -&gt; [String] -&gt; [String]
forall a. a -&gt; [a] -&gt; [a]
</span><span class="hs-glyph hs-var">:</span></span><span class="annot"><span class="annottext">[String]
</span><a href="#local-6989586621679618500"><span class="hs-identifier hs-var">xs</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-34"></span><span>        </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679618502"><span class="hs-identifier hs-var">n</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Bool
forall a. Ord a =&gt; a -&gt; a -&gt; Bool
</span><span class="hs-operator hs-var">&gt;</span></span><span>  </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">0</span></span><span> </span><span class="annot"><span class="annottext">Bool -&gt; Bool -&gt; Bool
</span><span class="hs-operator hs-var">&amp;&amp;</span></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;)&quot;</span></span><span> </span><span class="annot"><span class="annottext">String -&gt; String -&gt; Bool
forall a. Eq a =&gt; [a] -&gt; [a] -&gt; Bool
</span><a href="../../base/src/Data.OldList.html#isSuffixOf"><span class="hs-operator hs-var">`isSuffixOf`</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679618501"><span class="hs-identifier hs-var">x</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int -&gt; [String] -&gt; [String]
</span><a href="#local-6989586621679618503"><span class="hs-identifier hs-var">filterPar'</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679618502"><span class="hs-identifier hs-var">n</span></a></span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="../../base/src/GHC.Num.html#-"><span class="hs-glyph hs-var">-</span></a></span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">1</span></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">[String]
</span><a href="#local-6989586621679618500"><span class="hs-identifier hs-var">xs</span></a></span><span>
</span><span id="line-35"></span><span>        </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679618502"><span class="hs-identifier hs-var">n</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Bool
forall a. Ord a =&gt; a -&gt; a -&gt; Bool
</span><span class="hs-operator hs-var">&gt;</span></span><span>  </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">0</span></span><span>                       </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int -&gt; [String] -&gt; [String]
</span><a href="#local-6989586621679618503"><span class="hs-identifier hs-var">filterPar'</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679618502"><span class="hs-identifier hs-var">n</span></a></span><span> </span><span class="annot"><span class="annottext">[String]
</span><a href="#local-6989586621679618500"><span class="hs-identifier hs-var">xs</span></a></span><span>
</span><span id="line-36"></span><span>        </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../base/src/GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span>                    </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679618501"><span class="hs-identifier hs-var">x</span></a></span><span class="annot"><span class="annottext">String -&gt; [String] -&gt; [String]
forall a. a -&gt; [a] -&gt; [a]
</span><span class="hs-glyph hs-var">:</span></span><span class="annot"><span class="annottext">Int -&gt; [String] -&gt; [String]
</span><a href="#local-6989586621679618503"><span class="hs-identifier hs-var">filterPar'</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679618502"><span class="hs-identifier hs-var">n</span></a></span><span> </span><span class="annot"><span class="annottext">[String]
</span><a href="#local-6989586621679618500"><span class="hs-identifier hs-var">xs</span></a></span><span>
</span><span id="line-37"></span><span>
</span><span id="line-38"></span><span>      </span><span id="local-6989586621679618494"><span class="annot"><span class="annottext">filterPar :: [String] -&gt; [String]
</span><a href="#local-6989586621679618494"><span class="hs-identifier hs-var hs-var">filterPar</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int -&gt; [String] -&gt; [String]
</span><a href="#local-6989586621679618503"><span class="hs-identifier hs-var">filterPar'</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">0</span></span><span>
</span><span id="line-39"></span><span>
</span><span id="line-40"></span><span>  </span><span class="hs-keyword">in</span><span> </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">(String -&gt; Bool) -&gt; [String] -&gt; [String]
forall a. (a -&gt; Bool) -&gt; [a] -&gt; [a]
</span><a href="../../base/src/GHC.List.html#dropWhile"><span class="hs-identifier hs-var">dropWhile</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Bool -&gt; Bool
</span><span class="hs-identifier hs-var">not</span></span><span> </span><span class="annot"><span class="annottext">(Bool -&gt; Bool) -&gt; (String -&gt; Bool) -&gt; String -&gt; Bool
forall b c a. (b -&gt; c) -&gt; (a -&gt; b) -&gt; a -&gt; c
</span><a href="../../base/src/GHC.Base.html#."><span class="hs-operator hs-var">.</span></a></span><span> </span><span class="annot"><span class="annottext">String -&gt; Bool
</span><a href="#local-6989586621679618506"><span class="hs-identifier hs-var">numeric</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">[String] -&gt; [String]
</span><a href="#local-6989586621679618494"><span class="hs-identifier hs-var">filterPar</span></a></span><span> </span><span class="annot"><span class="annottext">([String] -&gt; [String])
-&gt; (String -&gt; [String]) -&gt; String -&gt; [String]
forall b c a. (b -&gt; c) -&gt; (a -&gt; b) -&gt; a -&gt; c
</span><a href="../../base/src/GHC.Base.html#."><span class="hs-operator hs-var">.</span></a></span><span> </span><span class="annot"><span class="annottext">String -&gt; [String]
</span><a href="../../base/src/Data.OldList.html#words"><span class="hs-identifier hs-var">words</span></a></span><span> </span><span class="annot"><span class="annottext">(String -&gt; [String]) -&gt; String -&gt; [String]
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679618507"><span class="hs-identifier hs-var">str</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-41"></span><span>    </span><span class="hs-special">(</span><span id="local-6989586621679618489"><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679618489"><span class="hs-identifier hs-var">ver</span></a></span></span><span class="annot"><span class="hs-glyph hs-type">:</span></span><span class="annot"><span class="annottext">[String]
</span><span class="hs-identifier">_</span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span>
</span><span id="line-42"></span><span>      </span><span class="hs-comment">-- take the first two version components</span><span>
</span><span id="line-43"></span><span>      </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621679618487"><span class="annot"><span class="annottext">isDot :: Char -&gt; Bool
</span><a href="#local-6989586621679618487"><span class="hs-identifier hs-var hs-var">isDot</span></a></span></span><span>         </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Char -&gt; Char -&gt; Bool
forall a. Eq a =&gt; a -&gt; a -&gt; Bool
</span><span class="hs-operator hs-var">==</span></span><span> </span><span class="annot"><span class="annottext">Char
</span><span class="hs-char">'.'</span></span><span class="hs-special">)</span><span>
</span><span id="line-44"></span><span>          </span><span class="hs-special">(</span><span id="local-6989586621679618486"><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679618486"><span class="hs-identifier hs-var">major</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621679618485"><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679618485"><span class="hs-identifier hs-var">rest</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(Char -&gt; Bool) -&gt; String -&gt; (String, String)
forall a. (a -&gt; Bool) -&gt; [a] -&gt; ([a], [a])
</span><a href="../../base/src/GHC.List.html#break"><span class="hs-identifier hs-var">break</span></a></span><span> </span><span class="annot"><span class="annottext">Char -&gt; Bool
</span><a href="#local-6989586621679618487"><span class="hs-identifier hs-var">isDot</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679618489"><span class="hs-identifier hs-var">ver</span></a></span><span>
</span><span id="line-45"></span><span>          </span><span id="local-6989586621679618483"><span class="annot"><span class="annottext">minor :: String
</span><a href="#local-6989586621679618483"><span class="hs-identifier hs-var hs-var">minor</span></a></span></span><span>         </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(Char -&gt; Bool) -&gt; String -&gt; String
forall a. (a -&gt; Bool) -&gt; [a] -&gt; [a]
</span><a href="../../base/src/GHC.List.html#takeWhile"><span class="hs-identifier hs-var">takeWhile</span></a></span><span> </span><span class="annot"><span class="annottext">Char -&gt; Bool
</span><a href="../../base/src/GHC.Unicode.html#isDigit"><span class="hs-identifier hs-var">isDigit</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">(Char -&gt; Bool) -&gt; String -&gt; String
forall a. (a -&gt; Bool) -&gt; [a] -&gt; [a]
</span><a href="../../base/src/GHC.List.html#dropWhile"><span class="hs-identifier hs-var">dropWhile</span></a></span><span> </span><span class="annot"><span class="annottext">Char -&gt; Bool
</span><a href="#local-6989586621679618487"><span class="hs-identifier hs-var">isDot</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679618485"><span class="hs-identifier hs-var">rest</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-46"></span><span>      </span><span class="hs-keyword">in</span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679618486"><span class="hs-identifier hs-var">major</span></a></span><span> </span><span class="annot"><span class="annottext">String -&gt; String -&gt; String
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="../../base/src/GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;.&quot;</span></span><span> </span><span class="annot"><span class="annottext">String -&gt; String -&gt; String
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="../../base/src/GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679618483"><span class="hs-identifier hs-var">minor</span></a></span><span>
</span><span id="line-47"></span><span>    </span><span class="annot"><span class="annottext">[String]
</span><span class="hs-identifier">_</span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;&quot;</span></span><span>
</span><span id="line-48"></span></pre></body></html>